<%@ page language="java" isELIgnored="false" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Insert title here</title>
</head>
<body>
       <h1>登录页面</h1>
       <span>用户名</span><input id="username" type="text"><br>
       <span>密码</span><input id="password" type="text">
       <input type="button" value="登录" onclick="login()"/>

       <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.4.1.min.js"></script>
       <script type="text/javascript">
              function login() {
                  var username = $("#username").val();
                  var password = $("#password").val();

                  $.ajax({
                      url: '/user/login',
                      type: 'post',
                      async:false,
                      data:{
                          username:username,
                          password:password,
                      },
                      timeout:5000,
                      success:function (data) {
                          //有错就抛错
                          if(data.status=="0"){
                              alert(data.message);return;
                          }
                          //
                          var newUrl = '${pageContext.request.contextPath}'+"/"+data;
                          $(window).attr('location',newUrl);


                      },
                  })

              }
       </script>
</body>
</html>